<template>
  <el-dialog class="assign-role" title="分配角色" :visible="showRoleDialog" @close="closeDialog">
    <!-- 这里准备复选框 -->
    <!-- el-checkbox-group选中的是 当前用户所拥有的角色  需要绑定 当前用户拥有的角色-->
    <el-checkbox-group v-model="checkList">
      <!-- 选项 -->
      <el-checkbox v-for="itm in list" :key="itm.id" :label="itm.id">{{ itm.name }}</el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <el-button type="primary" size="small" @click="hAssignRoles">确定</el-button>
      <el-button size="small" @click="closeDialog">取消</el-button>
    </template>
  </el-dialog>
</template>

<script>
import { getRoleList } from '@/api/setting'
import { assignRoles } from '@/api/employees'
import { getUserDetailById } from '@/api/user'
export default {
  name: 'Assign',
  props: {
    showRoleDialog: {
      type: Boolean,
      default: false
    },
    curId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      checkList: [],
      list: []
    }
  },
  methods: {
    closeDialog() {
      this.$emit('assign-dialog')
    },
    async getRoleList() {
      const res = await getRoleList(1, 100)
      this.list = res.rows
      const data = await getUserDetailById(this.curId)
      this.checkList = data.roleIds
    },
    async hAssignRoles() {
      await assignRoles({ id: this.curId, roleIds: this.checkList })
      this.closeDialog()
      this.$message.success('分配成功!')
    }
  }
}
</script>
<style lang="scss" scoped>
.assign-role {
  ::v-deep {
    .el-checkbox {
      font-size: 30px;
    }
  }
}
</style>
